package com.yyq.dao;

import com.yyq.pojo.User;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.jdbc.SQL;
import org.mybatis.caches.redis.RedisCache;

import java.util.List;

/**
 * @Author yuanyueqiang
 * @Date 2021-11-29 23:58
 */
@CacheNamespace(implementation = RedisCache.class)
public interface UserDao {

    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "username",column = "username"),
            @Result(property = "orders",column = "id",javaType = List.class,
            many = @Many(select = "com.yyq.dao.OrderDao.getOrderByUserId"))
    })
    @Select("select * from user ")
    List<User> getUserAndOrder();

    @Select("select * from user where id=#{id}")
    User getUserById(Integer id);

    @Update("update user set username=#{username} where id=#{id}")
    void updateUser(User user);


    //--------------------------------多对多, 暂未完成
    @Select("select * from user u " +
            "left join user_role ur on u.id=ur.user_id ")
    List<User> getUserAndRole();

}
